<?php
declare (strict_types=1);

namespace app\common\model;

/**
 * Class Borrow
 * @package app\common\model
 */
class Borrow extends Base
{
    protected $autoWriteTimestamp = 'int';
    protected $append=['status_name'];

    /**
     * 归还
     */
    const STATUS_2 = 2;

    /**
     * book #
     *
     * @auth kouweihong
     * @date 2020/11/25
     * @return \think\model\relation\HasOne
     */
    public function book()
    {
        return $this->hasOne(Book::class, 'id', 'book_id')->joinType('left');
    }

    /**
     * user #
     *
     * @auth kouweihong
     * @date 2020/11/25
     * @return \think\model\relation\HasOne
     */
    public function user()
    {
        return $this->hasOne(User::class, 'id', 'user_id')->joinType('left')->where('user_type', User::USER_TYPE_10);
    }

    public function getStatusNameAttr($value, $data)
    {
        return $data['status'] == 0 ? '借阅中' : '已归还';
    }
}
